import request from 'src/axios'

/**
 * @description 分页查询流程模型
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const pageModel = (params: object) => {
  return request.get('/flow/model/page', { params })
}

/**
 * @description 分页查询流程模型
 * @param { String } params 查询参数
 * @returns Promise
 */
export const viewModel = (id: string) => {
  return request.get('/flow/model/view', { params: { id } })
}

/**
 * @description 分页查询流程定义
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const pageProcessDef = (params: object) => {
  return request.get('/flow/processDef/page', { params })
}

/**
 * @description 分页查询我的发起
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const pageProcessInitiate = (params: object) => {
  return request.get('/flow/process/page/initiate', { params })
}

/**
 * @description 分页查询待办任务
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const pageUndoeTask = (params: object) => {
  return request.get('/flow/task/page/undone', { params })
}

/**
 * @description 分页查询已办任务
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const pageDoneTask = (params: object) => {
  return request.get('/flow/task/page/done', { params })
}

/**
 * @description 分页查询我的抄送
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const pageCCTask = (params: object) => {
  return request.get('/flow/task/page/cc', { params })
}

/**
 * @description 新增流程
 * @param { Object } data 新增数据
 * @returns Promise
 */
export const saveModel = (data: object) => {
  return request.post('/flow/model', data)
}

/**
 * @description 删除流程
 * @param { String } id 主键
 * @returns Promise
 */
export const deleteModel = (id: string) => {
  return request.delete('/flow/model', { data: { id } })
}

/**
 * @description 发布流程
 * @param { String } id 主键
 * @returns Promise
 */
export const deployModel = (id: string) => {
  return request.post('/flow/model/deploy', { id })
}

/**
 * @description 上传流程
 * @param { File } file 流程文件
 * @returns Promise
 */
export const uploadProcessDef = (file: File) => {
  const param = new FormData()
  param.append('file', file)
  return request.post('/flow/processDef/upload', param, { headers: { 'Content-Type': 'multipart/form-data' } })
}

/**
 * @description 删除流程
 * @param { String } id 流程信息主键
 * @returns Promise
 */
export const deleteProcessDef = (id: string) => {
  return request.delete('/flow/processDef', { data: { id } })
}

/**
 * @description 启动流程
 * @param { Object } data 启动数据
 * @returns Promise
 */
export const startProcess = (data: object) => {
  return request.post('/flow/task/start', data)
}

/**
 * @description 撤消流程
 * @param { Object } data 撤销数据
 * @returns Promise
 */
export const cancelProcess = (data: object) => {
  return request.post('/flow/process/cancel', data)
}

/**
 * @description 激活流程
 * @param { String } id 主键
 * @returns Promise
 */
export const activateProcessDef = (id: string) => {
  return request.post('/flow/processDef/activate', { id })
}

/**
 * @description 挂起流程
 * @param { String } id 主键
 * @returns Promise
 */
export const suspendProcessDef = (id: string) => {
  return request.post('/flow/processDef/suspend', { id })
}

/**
 * @description 转办任务
 * @param { Object } data 转办参数
 * @returns Promise
 */
export const transformTask = (data: object) => {
  return request.put('/flow/task/transform', data)
}

/**
 * @description 委派任务
 * @param { Object } data 转办参数
 * @returns Promise
 */
export const delegateTask = (data: object) => {
  return request.put('/flow/task/delegate', data)
}

/**
 * @description 认领任务
 * @param { String } id 主键
 * @returns Promise
 */
export const claimTask = (id: string) => {
  return request.put('/flow/task/claim', { id })
}

/**
 * @description 取消认领任务
 * @param { String } id 主键
 * @returns Promise
 */
export const cancelClaimTask = (id: string) => {
  return request.put('/flow/task/cancel', { id })
}

/**
 * @description 审核
 * @param { Object } data 审核参数
 * @returns Promise
 */
export const completeTask = (data: object) => {
  return request.post('/flow/task/complete', data)
}

/**
 * @description 查看流程历史
 * @param { String } businessKey 业务标识
 * @returns Promise
 */
export const listHistory = (businessKey: string) => {
  return request.get('/flow/task/historic', { params: { businessKey } })
}

/**
 * @description 跟踪流程历史
 * @param { String } processInsId 流程实例
 * @returns Promise
 */
export const trace = (processInsId: string) => {
  return request.get('/flow/task/trace', { params: { processInsId } })
}

/**
 * @description 查询租户
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const listTenant = (params?: object) => {
  return request.get('/flow/model/page/tenant', { params })
}

/**
 * @description 分页查询审核人
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const pageAssginee = (params: object) => {
  return request.get('/flow/model/page/user', { params })
}

/**
 * @description 分页查询审核组
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const pageGroup = (params: object) => {
  return request.get('/flow/model/page/role', { params })
}
